
QENV_FILE				?= $(SHARE_DIR_COMM)/qemu-run.env

#### qemu configs ####
QEMU_SMP				?= 2
QEMU_MEM				?= 1024
QEMU_SERIAL				?= none


#### qemu options ####
QEO_BASE				?= -nographic

QEO_SMP					?= -smp $(QEMU_SMP)
QEO_MEM					?= -m $(QEMU_MEM)

QEO_KL_ARGS				?= -append "$(KL_ARGS)"

# QEO_EXTRA may be specified by command line
# __QEO_EXTRA refer to qemu-xxx-gdb
QEO_EXTRA				?= $(__QEO_EXTRA)

# serial device
#  stdio:	-serial stdio
#  pty:		-serial pty					minicom -D /dev/pts/X
#  file:	-serial file:filename.log	tail -f filename.log
#  udp:		-serial udp::55550			nc(netcat) -u -l -p 55550
#  tcp:		-serial tcp::55500			nc(netcat) -l -p 55500
QEO_SERIAL_file			= -serial file:$(EELDIR)/serial0.log -serial file:$(EELDIR)/serial1.log
QEO_SERIAL_pty			= -serial pty -serial pty
QEO_SERIAL_udp			= -serial udp::55550 -serial udp::55551
QEO_SERIAL_tcp			= -serial tcp:localhost:55500 -serial tcp:localhost:55501
QEO_SERIAL				?= $(QEO_SERIAL_$(QEMU_SERIAL))

QEO_NET					?= -netdev user,id=net0 -device virtio-net-device,netdev=net0
QEO_RNG					?= -object rng-random,filename=/dev/urandom,id=rng0 \
							-device virtio-rng-pci,rng=rng0,max-bytes=1024,period=1000

# https://wiki.qemu.org/Documentation/9psetup
# mount -t 9p mnt_comm /mnt/
# mount -t 9p mnt_arch /mnt/arch [for binaries, rw]
# mount -t 9p mnt_eel $(abspath $(EELDIR)) [for symbol link, readonly]
QEO_SHARE				?= -fsdev local,id=share_comm,path=$(SHARE_DIR_COMM),security_model=none \
							-device virtio-9p-device,fsdev=share_comm,mount_tag=mnt_comm \
							-fsdev local,id=share_arch,path=$(SHARE_DIR_ARCH),security_model=none \
							-device virtio-9p-device,fsdev=share_arch,mount_tag=mnt_arch \
							-fsdev local,id=share_eel,path=$(EELDIR),security_model=passthrough,readonly=on \
							-device virtio-9p-device,fsdev=share_eel,mount_tag=mnt_eel

QEO_PRE					+= $(QEO_BASE)
QEO_PRE					+= $(QEO_SMP)
QEO_PRE					+= $(QEO_MEM)
QEO_PRE					+= $(QEO_CPU)

QEO_POST				+= $(QEO_SEMIHOST)
QEO_POST				+= $(QEO_SERIAL)
QEO_POST				+= $(QEO_NET)
QEO_POST				+= $(QEO_RNG)
# custom: QEO_BOARD
QEO_POST				+= $(QEO_BOARD)
QEO_POST				+= $(QEO_SHARE)

QEMU_DEPS-uboot			+= $(UB_IMAGE)

QEMU_DEPS-kernel		+= __share_dir $(KL_IMAGE) $(DTB_IMAGE)
# QEMU_DEPS-kernel		+= $(QENV_FILE)
QEMU_DEPS-kernel		+= qemu-env
ifneq ($(KL_EMBED_RFS),1)
QEMU_DEPS-kernel		+= $(RFS_IMAGE)
endif

ifeq ($(ARM_TEE),1)
QEMU_DEPS-uboot			+= $(TF_A_IMGS)
DUMP_DT					?= dump_$(ARCH)_tee
else
DUMP_DT					?= dump_$(ARCH)
endif
